from selenium.webdriver.common.by import By

from autoTest_ceshopAdmin.base_page.base import Base
from autoTest_ceshopAdmin.utils.log_util import logger


class LoginPage(Base):

    usernameBox_loc = (By.XPATH,"/html/body/form/table/tbody/tr/td[2]/table/tbody/tr[1]/td[2]/input")

    passwordBox_loc = (By.XPATH,"/html/body/form/table/tbody/tr/td[2]/table/tbody/tr[2]/td[2]/input")

    loginBtn_loc = (By.XPATH,"/html/body/form/table/tbody/tr/td[2]/table/tbody/tr[4]/td[2]/input")

    actualRes_loc = (By.XPATH,'//*[@id="submenu-div"]/ul/li[8]/a')
    Res_loc = (By.XPATH,'//table[@align="center"]/tbody/tr[1]/td[2]')

    heardFrame_loc = (By.XPATH,'//*[@id="header-frame"]')

    # 登录
    def longinSys(self,username,password):

        # 填写账号
        logger.info("输入用户名")
        self.input_data(self.usernameBox_loc,username)
        # 填写密码
        logger.info("输入密码")
        self.input_data(self.passwordBox_loc,password)
        # 点击登录按钮
        logger.info("点击登录按钮")
        self.click_element(self.loginBtn_loc)

    # 获取文本信息
    def elementText(self,flag=True):
        if flag:
            logger.info("切换表单")
            self.switchFrame(self.heardFrame_loc)
            logger.info("获取文本信息")
            text = self.getText(self.actualRes_loc)
        else:
            logger.info("获取文本信息")
            text = self.getText(self.Res_loc)
        return text


